home *** CD-ROM | disk | FTP | other *** search
/ TeX 1995 July / TeX CD-ROM July 1995 (Disc 1)(Walnut Creek)(1995).ISO / macros / latex209 / contrib / pslatex / fonts / afm2tfm.c < prev    next >
C/C++ Source or Header  |  1992-09-09  |  35KB  |  1,294 lines

  1. /*
  2.  *   This program converts AFM files to TeX TFM files, and optionally
  3.  *   to TeX VPL files that retain all kerning and ligature information.
  4.  *   Both files make the characters not normally encoded by TeX available
  5.  *   by character codes greater than 127.
  6.  */
  7.  
  8. /*   (Modified by Don Knuth from Tom Rokicki's pre-VPL version.) */
  9.  
  10. /*   (Modified again to preserve Adobe encoding by Mario Wolczko.) */
  11.  
  12. #include <stdio.h>
  13. #ifdef SYSV
  14. #include <string.h>
  15. #else
  16. #ifdef VMS
  17. #include <string.h>
  18. #else
  19. #include <strings.h>
  20. #endif
  21. #endif
  22. #include <math.h>
  23.  
  24. #ifdef MSDOS
  25. #define WRITEBIN "wb"
  26. #else
  27. #define WRITEBIN "w"
  28. #endif
  29.  
  30. char *texencoding[] = {
  31.    "", "", "", "", "", "", "",
  32.    "", "", "", "", "", "", "",
  33.    "", "", "", "", "", "",
  34.    "", "", "", "", "", "", "", "",
  35.    "", "", "", "", "space", "exclam", "quotedbl", "numbersign",
  36.    "dollar", "percent", "ampersand", "quoteright", "parenleft", "parenright",
  37.    "asterisk", "plus", "comma", "hyphen", "period", "slash", "zero", "one",
  38.    "two", "three", "four", "five", "six", "seven", "eight", "nine", "colon",
  39.    "semicolon", "less", "equal", "greater", "question", "at", "A", "B", "C",
  40.    "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R",
  41.    "S", "T", "U", "V", "W", "X", "Y", "Z", "bracketleft", "backslash",
  42.    "bracketright", "asciicircum", "underscore", "quoteleft", "a", "b", "c", "d",
  43.    "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", "p", "q", "r", "s",
  44.    "t", "u", "v", "w", "x", "y", "z", "braceleft", "bar", "braceright",
  45.    "asciitilde", "" } ;
  46. /*
  47.  *   The above layout corresponds to TeX Typewriter Type and is compatible
  48.  *   with TeX Text because the position of ligatures is immaterial.
  49.  */
  50.  
  51. /*
  52.  *   This is what we store Adobe data in.
  53.  */
  54. struct adobeinfo {
  55.    struct adobeinfo *next ;
  56.    int adobenum, texnum, width ;
  57.    char *adobename ;
  58.    int llx, lly, urx, ury ;
  59.    struct lig *ligs ;
  60.    struct kern *kerns ;
  61.    struct pcc *pccs ;
  62.    int wptr, hptr, dptr, iptr ;
  63. } *adobechars, *adobeptrs[256], *texptrs[256],
  64.   *uppercase[256], *lowercase[256] ;
  65. struct lig {
  66.    struct lig *next ;
  67.    char *succ, *sub ;
  68. } ;
  69. struct kern {
  70.    struct kern *next ;
  71.    char *succ ;
  72.    int delta ;
  73. } ;
  74. struct pcc {
  75.    struct pcc *next ;
  76.    char * partname ;
  77.    int xoffset, yoffset ;
  78. } ;
  79.  
  80. FILE *afmin, *vplout, *tfmout ;
  81. char inname[200], outname[200] ; /* names of input and output files */
  82. char buffer[255]; /* input buffer (modified while parsing) */
  83. char obuffer[255] ; /* unmodified copy of input buffer */
  84. char *param ; /* current position in input buffer */
  85. char *fontname = "Unknown" ;
  86. char *codingscheme = "Unspecified" ;
  87. float italicangle = 0.0 ;
  88. char fixedpitch ;
  89. char makevpl ;
  90. int xheight = 400 ;
  91. int fontspace ;
  92. int bc, ec ;
  93. long cksum ;
  94. float efactor = 1.0, slant = 0.0 ;
  95. double newslant ;
  96. char titlebuf[100] ;
  97.  
  98. void
  99. error(s)
  100. register char *s ;
  101. {
  102.    extern void exit() ;
  103.  
  104.    (void)fprintf(stderr, "%s\n", s) ;
  105.    if (obuffer[0]) {
  106.       (void)fprintf(stderr, "%s\n", obuffer) ;
  107.       while (param > buffer) {
  108.          (void)fprintf(stderr, " ") ;
  109.          param-- ;
  110.       }
  111.       (void)fprintf(stderr, "^\n") ;
  112.    }
  113.    if (*s == '!')
  114.       exit(1) ;
  115. }
  116.  
  117. int
  118. transform(x,y)
  119.    register int x,y ;
  120. {
  121.    register double acc ;
  122.    acc = efactor * x + slant *y ;
  123.    return (int)(acc>=0? acc+0.5 : acc-0.5 ) ;
  124. }
  125.  
  126. int
  127. getline() {
  128.    register char *p ;
  129.    register int c ;
  130.  
  131.    param = buffer ;
  132.    for (p=buffer; (c=getc(afmin)) != EOF && c != 10;)
  133.       *p++ = c ;
  134.    *p = 0 ;
  135.    (void)strcpy(obuffer, buffer) ;
  136.    if (p == buffer && c == EOF)
  137.       return(0) ;
  138.    else
  139.       return(1) ;
  140. }
  141.  
  142. char *interesting[] = { "FontName", "ItalicAngle", "IsFixedPitch",
  143.    "XHeight", "C", "KPX", "CC", "EncodingScheme", NULL} ; 
  144. #define FontName (0)
  145. #define ItalicAngle (1)
  146. #define IsFixedPitch (2)
  147. #define XHeight (3)
  148. #define C (4)
  149. #define KPX (5)
  150. #define CC (6)
  151. #define EncodingScheme (7)
  152. #define NONE (-1)
  153. int
  154. interest(s)
  155. char *s ;
  156. {
  157.    register char **p ;
  158.    register int n ;
  159.  
  160.    for (p=interesting, n=0; *p; p++, n++)
  161.       if (strcmp(s, *p)==0)
  162.          return(n) ;
  163.    return(NONE) ;
  164. }
  165.  
  166. char *
  167. mymalloc(len)
  168. int len ;
  169. {
  170.    register char *p ;
  171.    extern char *malloc() ;
  172.  
  173.    p = malloc((unsigned)len) ;
  174.    if (p==NULL)
  175.       error("! out of memory") ;
  176.    return(p) ;
  177. }
  178.  
  179. char *
  180. paramnewstring() {
  181.    register char *p, *q ;
  182.  
  183.    p = param ;
  184.    while (*p > ' ')
  185.       p++ ;
  186.    q = mymalloc((int)(p-param+1)) ;
  187.    if (*p != 0)
  188.       *p++ = 0 ;
  189.    (void)strcpy(q, param) ;
  190.    while (*p && *p <= ' ')
  191.       p++ ;
  192.    param = p ;
  193.    return(q) ;
  194. }
  195.  
  196. char *
  197. paramstring() {
  198.    register char *p, *q ;
  199.  
  200.    p = param ;
  201.    while (*p > ' ')
  202.       p++ ;
  203.    q = param ;
  204.    if (*p != 0)
  205.       *p++ = 0 ;
  206.    while (*p && *p <= ' ')
  207.       p++ ;
  208.    param = p ;
  209.    return(q) ;
  210. }
  211.  
  212. int
  213. paramnum() {
  214.    register char *p ;
  215.    int i ;
  216.  
  217.    p = paramstring() ;
  218.    if (sscanf(p, "%d", &i) != 1)
  219.       error("! integer expected") ;
  220.    return(i) ;
  221. }
  222.  
  223. float
  224. paramfloat() {
  225.    register char *p ;
  226.    float i ;
  227.  
  228.    p = paramstring() ;
  229.    if (sscanf(p, "%f", &i) != 1)
  230.       error("! number expected") ;
  231.    return(i) ;
  232. }
  233.  
  234. struct adobeinfo *
  235. newchar() {
  236.    register struct adobeinfo *ai ;
  237.  
  238.    ai = (struct adobeinfo *)mymalloc(sizeof(struct adobeinfo)) ;
  239.    ai->adobenum = -1 ;
  240.    ai->texnum = -1 ;
  241.    ai->width = -1 ;
  242.    ai->adobename = NULL ;
  243.    ai->llx = -1 ;
  244.    ai->lly = -1 ;
  245.    ai->urx = -1 ;
  246.    ai->ury = -1 ;
  247.    ai->ligs = NULL ;
  248.    ai->kerns = NULL ;
  249.    ai->pccs = NULL ;
  250.    ai->next = adobechars ;
  251.    adobechars = ai ;
  252.    return(ai) ;
  253. }
  254.  
  255. struct kern *
  256. newkern() {
  257.    register struct kern *nk ;
  258.  
  259.    nk = (struct kern *)mymalloc(sizeof(struct kern)) ;
  260.    nk->next = NULL ;
  261.    nk->succ = NULL ;
  262.    nk->delta = 0 ;
  263.    return(nk) ;
  264. }
  265.  
  266. struct pcc *
  267. newpcc() {
  268.    register struct pcc *np ;
  269.  
  270.    np = (struct pcc *)mymalloc(sizeof(struct pcc)) ;
  271.    np->next = NULL ;
  272.    np->partname = NULL ;
  273.    np->xoffset = 0 ;
  274.    np->yoffset = 0 ;
  275.    return(np) ;
  276. }
  277.  
  278. struct lig *
  279. newlig() {
  280.    register struct lig *nl ;
  281.  
  282.    nl = (struct lig *)mymalloc(sizeof(struct lig)) ;
  283.    nl->next = NULL ;
  284.    nl->succ = NULL ;
  285.    nl->sub = NULL ;
  286.    return(nl) ;
  287. }
  288.  
  289. void
  290. expect(s)
  291. char *s ;
  292. {
  293.    if (strcmp(paramstring(), s) != 0) {
  294.       (void)fprintf(stderr, "%s expected: ", s) ;
  295.       error("! syntax error") ;
  296.    }
  297. }
  298.  
  299. void
  300. handlechar() { /* an input line beginning with C */
  301.    register struct adobeinfo *ai ;
  302.    register struct lig *nl ;
  303.  
  304.    ai = newchar() ;
  305.    ai->adobenum = paramnum() ;
  306.    expect(";") ;
  307.    expect("WX") ;
  308.    ai->width = transform(paramnum(),0) ;
  309.    if (ai->adobenum >= 0 && ai->adobenum < 256) {
  310.       adobeptrs[ai->adobenum] = ai ;
  311.       cksum = (cksum<<1) ^ ai->width ;
  312.    }
  313.    expect(";") ;
  314.    expect("N") ;
  315.    ai->adobename = paramnewstring() ;
  316.    expect(";") ;
  317.    expect("B") ;
  318.    ai->llx = paramnum() ;
  319.    ai->lly = paramnum() ;
  320.    ai->llx = transform(ai->llx, ai->lly) ;
  321.    ai->urx = paramnum() ;
  322.    ai->ury = paramnum() ;
  323.    ai->urx = transform(ai->urx, ai->ury) ;
  324. /* We need to avoid negative heights or depths. They break accents in
  325.    math mode, among other things.  */
  326.    if (ai->lly > 0)
  327.       ai->lly = 0 ;
  328.    if (ai->ury < 0)
  329.       ai->ury = 0 ;
  330.    expect(";") ;
  331. /* Now look for ligatures (which aren't present in fixedpitch fonts) */
  332.    while (*param == 'L') {
  333.       expect("L") ;
  334.       nl = newlig() ;
  335.       nl->succ = paramnewstring() ;
  336.       nl->sub = paramnewstring() ;
  337.       nl->next = ai->ligs ;
  338.       ai->ligs = nl ;
  339.       expect(";") ;
  340.    }
  341.    if (strcmp(ai->adobename, "space")==0) {
  342.       fontspace = ai->width ;
  343.       nl = newlig() ;        /* space will act as zero-width Polish crossbar */
  344.       nl->succ = "l" ;       /* when used by plain TeX's \l or \L macros */
  345.       nl->sub = "lslash" ;
  346.       nl->next = ai->ligs ;
  347.       ai->ligs = nl ;
  348.       nl = newlig() ;
  349.       nl->succ = "L" ;
  350.       nl->sub = "Lslash" ;
  351.       nl->next = ai->ligs ;
  352.       ai->ligs = nl ;
  353.    } else if (strcmp(ai->adobename, "question")==0) {
  354.       nl = newlig() ;
  355.       nl->succ = "quoteleft" ;
  356.       nl->sub = "questiondown" ;
  357.       nl->next = ai->ligs ;
  358.       ai->ligs = nl ;
  359.    } else if (strcmp(ai->adobename, "exclam")==0) {
  360.       nl = newlig() ;
  361.       nl->succ = "quoteleft" ;
  362.       nl->sub = "exclamdown" ;
  363.       nl->next = ai->ligs ;
  364.       ai->ligs = nl ;
  365.    } else if (! fixedpitch) {
  366.       if (strcmp(ai->adobename, "hyphen")==0) {
  367.          nl = newlig() ;
  368.          nl->succ = "hyphen" ;
  369.          nl->sub = "endash" ;
  370.          nl->next = ai->ligs ;
  371.          ai->ligs = nl ;
  372.       } else if (strcmp(ai->adobename, "endash")==0) {
  373.          nl = newlig() ;
  374.          nl->succ = "hyphen" ;
  375.          nl->sub = "emdash" ;
  376.          nl->next = ai->ligs ;
  377.          ai->ligs = nl ;
  378.       } else if (strcmp(ai->adobename, "quoteleft")==0) {
  379.          nl = newlig() ;
  380.          nl->succ = "quoteleft" ;
  381.          nl->sub = "quotedblleft" ;
  382.          nl->next = ai->ligs ;
  383.          ai->ligs = nl ;
  384.       } else if (strcmp(ai->adobename, "quoteright")==0) {
  385.          nl = newlig() ;
  386.          nl->succ = "quoteright" ;
  387.          nl->sub = "quotedblright" ;
  388.          nl->next = ai->ligs ;
  389.          ai->ligs = nl ;
  390.       }
  391.    }
  392. }
  393.  
  394. struct adobeinfo *
  395. findadobe(p)
  396. char *p ;
  397. {
  398.    register struct adobeinfo *ai ;
  399.  
  400.    for (ai=adobechars; ai; ai = ai->next)
  401.       if (strcmp(p, ai->adobename)==0)
  402.          return(ai) ;
  403.    return(NULL) ;
  404. }
  405.  
  406. /* We ignore kerns before and after space characters, because (1) TeX
  407.  * is using the space only for Polish ligatures, and (2) TeX's
  408.  * boundarychar mechanisms are not oriented to kerns (they apply
  409.  * to both spaces and punctuation) so we don't want to use them. */
  410. void
  411. handlekern() { /* an input line beginning with KPX */
  412.    register struct adobeinfo *ai ;
  413.    register char *p ;
  414.    register struct kern *nk ;
  415.  
  416.    p = paramstring() ;
  417.    if (strcmp(p,"space")==0) return ;
  418.    ai = findadobe(p) ;
  419.    if (ai == NULL)
  420.       error("! kern char not found") ;
  421.    if (ai->adobenum<'0' || ai->adobenum>'9') {
  422. /* Ignore kerns after digits because they would mess up our nice tables */
  423.       nk = newkern() ;
  424.       nk->succ = paramnewstring() ;
  425.       if (strcmp(nk->succ,"space")==0) return ;
  426.       nk->delta = transform(paramnum(),0) ;
  427.       nk->next = ai->kerns ;
  428.       ai->kerns = nk ;
  429.     }
  430. }
  431.  
  432. void
  433. handleconstruct() { /* an input line beginning with CC */
  434.    register struct adobeinfo *ai ;
  435.    register char *p ;
  436.    register struct pcc *np ;
  437.    register int n ;
  438.    struct pcc *npp = NULL;
  439.  
  440.    p = paramstring() ;
  441.    ai = findadobe(p) ;
  442.    if (ai == NULL)
  443.       error("! composite character name not found") ;
  444.    n = paramnum() ;
  445.    expect(";") ;
  446.    while (n--) {
  447.       if (strcmp(paramstring(),"PCC") != 0) return ;
  448.         /* maybe I should expect("PCC") instead, but I'm playing it safe */
  449.       np = newpcc() ;
  450.       np->partname = paramnewstring() ;
  451.       if (findadobe(np->partname)==NULL) return ;
  452.       np->xoffset = paramnum() ;
  453.       np->yoffset = paramnum() ;
  454.       np->xoffset = transform(np->xoffset, np->yoffset) ;
  455.       if (npp) npp->next = np ;
  456.       else ai->pccs = np ;
  457.       npp = np ;
  458.       expect(";") ;
  459.    }
  460. }
  461.  
  462. void
  463. makeaccentligs() {
  464.    register struct adobeinfo *ai, *aci ;
  465.    register char *p ;
  466.    register struct lig *nl ;
  467.    for (ai=adobechars; ai; ai=ai->next) {
  468.       p = ai->adobename ;
  469.       if (strlen(p)>2)
  470.          if ((aci=findadobe(p+1)) && (aci->adobenum > 127)) {
  471.             nl = newlig() ;
  472.             nl->succ = mymalloc(2) ;
  473.             *(nl->succ + 1) = 0 ;
  474.             *(nl->succ) = *p ;
  475.             nl->sub = ai->adobename ;
  476.             nl->next = aci->ligs ;
  477.             aci->ligs = nl ;
  478.          }
  479.    }
  480. }
  481.  
  482. void
  483. readadobe() {
  484.    while (getline()) {
  485.       switch(interest(paramstring())) {
  486. case FontName:
  487.          fontname = paramnewstring() ;
  488.          break ;
  489. case EncodingScheme:
  490.          codingscheme = paramnewstring() ;
  491.          break ;
  492. case ItalicAngle:
  493.          italicangle = paramfloat() ;
  494.          break ;
  495. case IsFixedPitch:
  496.          if (*param == 't' || *param == 'T')
  497.             fixedpitch = 1 ;
  498.          else
  499.             fixedpitch = 0 ;
  500.          break ;
  501. case XHeight:
  502.          xheight = paramnum() ;
  503.          break ;
  504. case C:
  505.          handlechar() ;
  506.          break ;
  507. case KPX:
  508.          handlekern() ;
  509.          break ;
  510. case CC:
  511.          handleconstruct() ;
  512.          break ;
  513. default:
  514.          break ;
  515.       }
  516.    }
  517.    makeaccentligs() ;
  518. }
  519.  
  520. void
  521. assignchars() {
  522.    register char **p ;
  523.    register int i ;
  524.    register struct adobeinfo *ai ;
  525.    int nextfree = 128 ;
  526.  
  527. /*
  528.  *   First, we assign all those that match perfectly.
  529.  */
  530.    for (i=0, p=texencoding; i<128; i++, p++)
  531.       if ((ai=findadobe(*p)) && ai->adobenum >= 0) {
  532.          ai->texnum = i ;
  533.          texptrs[i] = ai ;
  534.       }
  535. /*
  536.  *   Next, we assign all the others whose codes are above 127, retaining
  537.  *   the adobe positions. */
  538.    for (ai=adobechars; ai; ai=ai->next)
  539.       if (ai->adobenum > 127 && ai->texnum<0) {
  540.          ai->texnum = ai->adobenum ;
  541.          texptrs[ai->adobenum] = ai ;
  542.       }
  543. /*   Finally, we map all remaining characters into free locations beginning
  544.  *   with 128, if we know how to construct those characters. */
  545.    for (ai=adobechars; ai; ai=ai->next)
  546.       if (ai->texnum<0 && (ai->adobenum>=0 || ai->pccs !=NULL)) {
  547.          while (texptrs[nextfree]) {
  548.             nextfree=(nextfree+1)&255 ;
  549.             if (nextfree==128) return ; /* all slots full */
  550.          }
  551.          ai->texnum = nextfree ;
  552.          texptrs[nextfree] = ai ;
  553.       }
  554. }
  555.  
  556. void
  557. upmap() { /* Compute uppercase mapping, when making a small caps font */
  558.    register struct adobeinfo *ai, *Ai ;
  559.    register char *p, *q ;
  560.    register struct pcc *np, *nq ;
  561.    char lwr[50] ;
  562.  
  563.    for (Ai=adobechars; Ai; Ai=Ai->next) {
  564.       p = Ai->adobename ;
  565.       if (*p>='A' && *p<='Z') {
  566.          q = lwr ;
  567.          for (; *p; p++)
  568.             *q++ = ((*p>='A' && *p<='Z') ? *p+32 : *p) ;
  569.          *q = 0;
  570.          if (ai=findadobe(lwr)) {
  571.             if (ai->texnum>=0) uppercase[ai->texnum] = Ai ;
  572.             if (Ai->texnum>=0) lowercase[Ai->texnum] = ai ;
  573.          }
  574.       }
  575.    }
  576. /* Note that, contrary to the normal true/false conventions,
  577.  * uppercase[i] is NULL and lowercase[i] is non-NULL when i is the
  578.  * ASCII code of an uppercase letter; and vice versa for lowercase letters */
  579.  
  580.    if (ai=findadobe("germandbls"))
  581.       if (Ai=findadobe("S")) { /* we also construct SS */
  582.          uppercase[ai->texnum] = ai ;
  583.          ai->width = Ai->width << 1 ;
  584.          ai->llx = Ai->llx ;
  585.          ai->lly = Ai->lly ;
  586.          ai->urx = Ai->width + Ai->urx ;
  587.          ai->ury = Ai->ury ;
  588.          ai->kerns = Ai->kerns ;
  589.          np = newpcc() ;
  590.          np->partname = "S" ;
  591.          nq = newpcc() ;
  592.          nq->partname = "S" ;
  593.          nq->xoffset = Ai->width ;
  594.          np->next = nq ;   
  595.          ai->pccs = np ;
  596.       }
  597.    if (ai=findadobe("dotlessi"))
  598.       uppercase[ai->texnum] = findadobe("I") ;
  599.    if (ai=findadobe("dotlessj"))
  600.       uppercase[ai->texnum] = findadobe("J") ;
  601. }
  602. /* The logic above seems to work well enough, but it leaves useless characters
  603.  * like `fi' and `fl' in the font if they were present initially,
  604.  * and it omits characters like `dotlessj' if they are absent initially */
  605.  
  606. /* Now we turn to computing the TFM file */
  607.  
  608. int lf, lh, nw, nh, nd, ni, nl, nk, ne, np ;
  609.  
  610. void
  611. write16(what)
  612. register short what ;
  613. {
  614.    (void)fputc(what >> 8, tfmout) ;
  615.    (void)fputc(what & 255, tfmout) ;
  616. }
  617.  
  618. void
  619. writearr(p, n)
  620. register long *p ;
  621. register int n ;
  622. {
  623.    while (n) {
  624.       write16((short)(*p >> 16)) ;
  625.       write16((short)(*p & 65535)) ;
  626.       p++ ;
  627.       n-- ;
  628.    }
  629. }
  630.  
  631. void
  632. makebcpl(p, s, n)
  633. register long *p ;
  634. register char *s ;
  635. register int n ;
  636. {
  637.    register long t ;
  638.    register long sc ;
  639.  
  640.    if (strlen(s) < n)
  641.       n = strlen(s) ;
  642.    t = ((long)n) << 24 ;
  643.    sc = 16 ;
  644.    while (n > 0) {
  645.       t |= ((long)(*(unsigned char *)s++)) << sc ;
  646.       sc -= 8 ;
  647.       if (sc < 0) {
  648.          *p++ = t ;
  649.          t = 0 ;
  650.          sc = 24 ;
  651.       }
  652.       n-- ;
  653.    }
  654.    *p++ = t ;
  655. }
  656.  
  657. int source[257] ;
  658. int unsort[257] ;
  659.  
  660. /*
  661.  *   Next we need a routine to reduce the number of distinct dimensions
  662.  *   in a TFM file. Given an array what[0]...what[oldn-1], we want to
  663.  *   group its elements into newn clusters, in such a way that the maximum
  664.  *   difference between elements of a cluster is as small as possible.
  665.  *   Furthermore, what[0]=0, and this value must remain in a cluster by
  666.  *   itself. Data such as `0 4 6 7 9' with newn=3 shows that an iterative
  667.  *   scheme in which 6 is first clustered with 7 will not work. So we
  668.  *   borrow a neat algorithm from METAFONT to find the true optimum.
  669.  *   Memory location what[oldn] is set to 0x7fffffffL for convenience.
  670.  */
  671. long nextd ; /* smallest value that will give a different mincover */
  672. int
  673. mincover(what,d) /* tells how many clusters result, given max difference d */
  674. register long d ;
  675. long *what ;
  676. {
  677.    register int m ;
  678.    register long l ;
  679.    register long *p ;
  680.  
  681.    nextd = 0x7fffffffL ;
  682.    p = what+1 ;
  683.    m = 1 ;
  684.    while (*p<0x7fffffffL) {
  685.       m++ ;
  686.       l = *p ;
  687.       while (*++p <= l+d) ;
  688.       if (*p-l < nextd) nextd = *p-l ;
  689.    }
  690.    return (m) ;
  691. }
  692.  
  693. void
  694. remap(what, oldn, newn)
  695. long *what ;
  696. int oldn, newn ;
  697. {
  698.    register int i, j ;
  699.    register long d, l ;
  700.  
  701.    what[oldn] = 0x7fffffffL ;
  702.    for (i=oldn-1; i>0; i--) {
  703.       d = what[i] ;
  704.       for (j=i; what[j+1]<d; j++) {
  705.          what[j] = what[j+1] ;
  706.          source[j] = source[j+1] ;
  707.       }
  708.       what[j] = d ;
  709.       source[j] = i ;
  710.    } /* Tom, don't let me ever catch you using bubblesort again! -- Don */
  711.  
  712.    i = mincover(what, 0L) ;
  713.    d = nextd ;
  714.    while (mincover(what,d+d)>newn) d += d ;
  715.    while (mincover(what,d)>newn) d = nextd ;
  716.  
  717.    i = 1 ;
  718.    j = 0 ;
  719.    while (i<oldn) {
  720.       j++ ;
  721.       l = what[i] ;
  722.       unsort[source[i]] = j ;
  723.       while (what[++i] <= l+d) {
  724.          unsort[source[i]] = j ;
  725.          if (i-j == oldn-newn) d = 0 ;
  726.       }
  727.       what[j] = (l+what[i-1])/2 ;
  728.    }
  729. }
  730.  
  731. /*
  732.  *   The next routine simply scales something.
  733.  *   Input is in 1000ths of an em.  Output is in FIXFACTORths of 1000.
  734.  */
  735. #define FIXFACTOR (0x100000L) /* 2^{20}, the unit fixnum */
  736. long
  737. scale(what)
  738. long what ;
  739. {
  740.    return(((what / 1000) << 20) +
  741.           (((what % 1000) << 20) + 500) / 1000) ;
  742. }
  743.  
  744. long *header, *charinfo, *width, *height, *depth, *ligkern, *kern, *tparam,
  745.      *italic ;
  746. long tfmdata[10000] ;
  747.  
  748. void
  749. buildtfm() {
  750.    register int i, j ;
  751.    register struct adobeinfo *ai ;
  752.  
  753.    header = tfmdata ;
  754.    header[0] = cksum ;
  755.    header[1] = 0xa00000 ; /* 10pt design size */
  756.    makebcpl(header+2, codingscheme, 39) ;
  757.    makebcpl(header+12, fontname, 19) ;
  758.    lh = 17 ;
  759.    charinfo = header + lh ;
  760.  
  761.    for (i=0; i<256 && adobeptrs[i]==NULL; i++) ;
  762.    bc = i ;
  763.    for (i=255; i>=0 && adobeptrs[i]==NULL; i--) ;
  764.    ec = i;
  765.    if (ec < bc)
  766.       error("! no Adobe characters") ;
  767.  
  768.    width = charinfo + (ec - bc + 1) ;
  769.    width[0] = 0 ;
  770.    nw++ ;
  771.    for (i=bc; i<=ec; i++)
  772.       if (ai=adobeptrs[i]) {
  773.          width[nw]=ai->width ;
  774.          for (j=1; width[j]!=ai->width; j++) ;
  775.          ai->wptr = j ;
  776.          if (j==nw)
  777.             nw++ ;
  778.       }
  779.    if (nw>256)
  780.       error("! 256 chars with different widths") ;
  781.    depth = width + nw ;
  782.    depth[0] = 0 ;
  783.    nd = 1 ;
  784.    for (i=bc; i<=ec; i++)
  785.       if (ai=adobeptrs[i]) {
  786.          depth[nd] = -ai->lly ;
  787.          for (j=0; depth[j]!=-ai->lly; j++) ;
  788.          ai->dptr = j ;
  789.          if (j==nd)
  790.             nd++ ;
  791.       }
  792.    if (nd > 16) {
  793.       remap(depth, nd, 16) ;
  794.       nd = 16 ;
  795.       for (i=bc; i<=ec; i++)
  796.          if (ai=adobeptrs[i])
  797.             ai->dptr = unsort[ai->dptr] ;
  798.    }
  799.    height = depth + nd ;
  800.    height[0] = 0 ;
  801.    nh = 1 ;
  802.    for (i=bc; i<=ec; i++)
  803.       if (ai=adobeptrs[i]) {
  804.          height[nh]=ai->ury ;
  805.          for (j=0; height[j]!=ai->ury; j++) ;
  806.          ai->hptr = j ;
  807.          if (j==nh)
  808.             nh++ ;
  809.       }
  810.    if (nh > 16) {
  811.       remap(height, nh, 16) ;
  812.       nh = 16 ;
  813.       for (i=bc; i<=ec; i++)
  814.          if (ai=adobeptrs[i])
  815.             ai->hptr = unsort[ai->hptr] ;
  816.    }
  817.    italic  = height + nh ;
  818.    italic[0] = 0 ;
  819.    ni = 1 ;
  820.    for (i=bc; i<=ec; i++)
  821.       if (ai=adobeptrs[i]) {
  822.          italic[ni] = ai->urx - ai->width ;
  823.          if (italic[ni]<0)
  824.             italic[ni] = 0 ;
  825.          for (j=0; italic[j]!=italic[ni]; j++) ;
  826.          ai->iptr = j ;
  827.          if (j==ni)
  828.             ni++ ;
  829.       }
  830.    if (ni > 64) {
  831.       remap(italic, ni, 64) ;
  832.       ni = 64 ;
  833.       for (i=bc; i<=ec; i++)
  834.          if (ai=adobeptrs[i])
  835.             ai->iptr = unsort[ai->iptr] ;
  836.    }
  837.  
  838.    for (i=bc; i<=ec; i++)
  839.       if (ai=adobeptrs[i])
  840.          charinfo[i-bc] = ((long)(ai->wptr)<<24) +
  841.                            ((long)(ai->hptr)<<20) +
  842.                             ((long)(ai->dptr)<<16) +
  843.                              ((long)(ai->iptr)<<10) ;
  844.  
  845.    ligkern = italic + ni ;
  846.    nl = 0 ; /* ligatures and kerns omitted from raw Adobe font */
  847.    kern = ligkern + nl ;
  848.    nk = 0 ;
  849.  
  850.    newslant = (double)slant - efactor * tan(italicangle*(3.1415926535/180.0)) ;
  851.    tparam = kern + nk ;
  852.    tparam[0] = (long)(FIXFACTOR * newslant + 0.5) ;
  853.    tparam[1] = scale((long)(fontspace /* *efactor+0.5 -miw */)) ;
  854.    tparam[2] = (fixedpitch ? 0 : scale((long)(300*efactor+0.5))) ;
  855.    tparam[3] = (fixedpitch ? 0 : scale((long)(100*efactor+0.5))) ;
  856.    tparam[4] = scale((long)xheight) ;
  857.    tparam[5] = scale((long)(1000*efactor+0.5)) ;
  858.    np = 6 ;
  859. }
  860.  
  861. void
  862. writesarr(what, len)
  863. long *what ;
  864. int len ;
  865. {
  866.    register long *p ;
  867.    int i ;
  868.  
  869.    p = what ;
  870.    i = len ;
  871.    while (i) {
  872.       *p = scale(*p) ;
  873.       p++ ;
  874.       i-- ;
  875.    }
  876.    writearr(what, len) ;
  877. }
  878.  
  879. void
  880. writetfm() {
  881.    lf = 6 + lh + (ec - bc + 1) + nw + nh + nd + ni + nl + nk + ne + np ;
  882.    write16(lf) ;
  883.    write16(lh) ;
  884.    write16(bc) ;
  885.    write16(ec) ;
  886.    write16(nw) ;
  887.    write16(nh) ;
  888.    write16(nd) ;
  889.    write16(ni) ;
  890.    write16(nl) ;
  891.    write16(nk) ;
  892.    write16(ne) ;
  893.    write16(np) ;
  894.    writearr(header, lh) ;
  895.    writearr(charinfo, ec-bc+1) ;
  896.    writesarr(width, nw) ;
  897.    writesarr(height, nh) ;
  898.    writesarr(depth, nd) ;
  899.    writesarr(italic, ni) ;
  900.    writearr(ligkern, nl) ;
  901.    writesarr(kern, nk) ;
  902.    writearr(tparam, np) ;
  903. }
  904.  
  905. /* OK, the TFM file is done! Now for our next trick, the VPL file. */
  906.  
  907. /* For TeX we want to compute a character height that works properly
  908.  * with accents. The following list of accents doesn't need to be complete. */
  909. char *accents[] = { "acute", "tilde", "caron", "dieresis", NULL} ;
  910. int
  911. texheight(ai)
  912. register struct adobeinfo *ai ;
  913. {
  914.    register char **p;
  915.    register struct adobeinfo *aci, *acci ;
  916.    if (*(ai->adobename + 1)) return (ai->ury) ; /* that was the simple case */
  917.    for (p=accents; *p; p++)  /* otherwise we look for accented letters */
  918.       if (aci=findadobe(*p)) {
  919.          strcpy(buffer,ai->adobename) ;
  920.          strcat(buffer,*p) ;
  921.          if (acci=findadobe(buffer)) return (acci->ury - aci->ury + xheight) ;
  922.       }
  923.    return (ai->ury) ;
  924. }
  925.  
  926. /* modified tgr to eliminate varargs problems */
  927.  
  928. #define vout(s)  fprintf(vplout, s)
  929. int level ; /* the depth of parenthesis nesting in VPL file being written */
  930.  
  931. void vlevout() {
  932.    register int l = level ;
  933.    while (l--) vout("   ") ;
  934. }
  935.  
  936. void vlevnlout() {
  937.    vout("\n") ;
  938.    vlevout() ;
  939. }
  940.  
  941. #define voutln(str) {fprintf(vplout,"%s\n",str);vlevout();}
  942. /*
  943. void
  944. voutln(s)
  945. char *s ;
  946. {
  947.    register char l ;
  948.    fprintf(vplout,"%s\n", s) ;
  949.    for (l=level; l; l--) vout("   ") ;
  950. }
  951. */
  952. #define voutln2(f,s) {fprintf(vplout,f,s);vlevnlout();}
  953. /*
  954. void
  955. voutln2(f,s)
  956. char *f, *s ;
  957. {
  958.    register char l ;
  959.    (void) sprintf(buffer, f, s) ;
  960.    fprintf(vplout,"%s\n", buffer) ;
  961.    for (l=level; l; l--) vout("   ") ;
  962. }
  963. */
  964. #define voutln3(f,a,b) {fprintf(vplout,f,a,b);vlevnlout();}
  965. /*
  966. void
  967. voutln3(f,s1,s2)
  968. char *f, *s1, *s2 ;
  969. {
  970.    register char l ;
  971.    (void) sprintf(buffer, f, s1, s2) ;
  972.    fprintf(vplout,"%s\n", buffer) ;
  973.    for (l=level; l; l--) vout("   ") ;
  974. }
  975. */
  976. void
  977. vleft()
  978. {
  979.    level++ ;
  980.    vout("(") ;
  981. }
  982.  
  983. void
  984. vright()
  985. {
  986.    level-- ;
  987.    voutln(")") ;
  988. }
  989.  
  990. char vcharbuf[6] ;
  991. char *vchar(c)
  992. int c ;
  993. {
  994.    if ((c>='0' && c<='9')||(c>='A' && c<='Z')||(c>='a' && c<='z'))
  995.       (void) sprintf(vcharbuf,"C %c", c) ;
  996.    else (void) sprintf(vcharbuf,"O %o", c) ;
  997.    return (vcharbuf) ;
  998. }
  999.  
  1000. void
  1001. writevpl()
  1002. {
  1003.    register int i ;
  1004.    register struct adobeinfo *ai ;
  1005.    register struct lig *nlig ;
  1006.    register struct kern *nkern ;
  1007.    register struct pcc *npcc ;
  1008.    struct adobeinfo *asucc, *asub, *api ;
  1009.    int xoff, yoff, ht ;
  1010.    char unlabeled ;
  1011.  
  1012.    voutln2("(VTITLE Created by %s)", titlebuf) ;
  1013.    voutln("(COMMENT Please edit that VTITLE if you edit this file)") ;
  1014.    (void)sprintf(obuffer, "%s%s%s%s", outname,
  1015.       (efactor==1.0? "" : efactor<1.0 ? "-N" : "-E"),
  1016.       (slant==0.0? "" : "-O"),
  1017.       (makevpl==1? "" : "-CSC")) ;
  1018.    if (strlen(obuffer)>19) { /* too long, will retain first 9 and last 10 */
  1019.       register char *p, *q ;
  1020.       for (p = &obuffer[9], q = &obuffer[strlen(obuffer)-10] ; p<&obuffer[19];
  1021.               p++, q++) *p = *q ;
  1022.       obuffer[19] = '\0' ;
  1023.    }
  1024.    voutln2("(FAMILY %s)" , obuffer) ;
  1025.    voutln2("(CODINGSCHEME %s)", codingscheme) ;
  1026.    voutln("(DESIGNSIZE R 10.0)") ;
  1027.    voutln("(DESIGNUNITS R 1000)") ;
  1028.    voutln("(COMMENT DESIGNSIZE (1 em) IS IN POINTS)") ;
  1029.    voutln("(COMMENT OTHER DIMENSIONS ARE MULTIPLES OF DESIGNSIZE/1000)") ;
  1030.    voutln2("(CHECKSUM O %lo)",cksum ^ 0xffffffff) ;
  1031.    vleft() ; voutln("FONTDIMEN") ;
  1032.    if (newslant)
  1033.       voutln2("(SLANT R %f)", newslant) ;
  1034.    voutln2("(SPACE D %d)", transform(fontspace,0)) ;
  1035.    if (! fixedpitch) {
  1036.       voutln2("(STRETCH D %d)", transform(200,0)) ;
  1037.       voutln2("(SHRINK D %d)", transform(100,0)) ;
  1038.    }
  1039.    voutln2("(XHEIGHT D %d)", xheight) ;
  1040.    voutln2("(QUAD D %d)", transform(1000,0)) ;
  1041.    voutln2("(EXTRASPACE D %d)", transform(fixedpitch ? fontspace : 111, 0)) ;
  1042.    vright() ;
  1043.    vleft() ; voutln("MAPFONT D 0");
  1044.    voutln2("(FONTNAME %s)", outname) ;
  1045.    voutln2("(FONTCHECKSUM O %lo)", cksum) ;
  1046.    vright() ;
  1047.    if (makevpl>1) {
  1048.       vleft() ; voutln("MAPFONT D 1");
  1049.       voutln2("(FONTNAME %s)", outname) ;
  1050.       voutln("(FONTAT D 800)") ;
  1051.       voutln2("(FONTCHECKSUM O %lo)", cksum) ;
  1052.       vright() ;
  1053.    }
  1054.  
  1055.    for (i=0; i<256 && texptrs[i]==NULL; i++) ;
  1056.    bc = i ;
  1057.    for (i=255; i>=0 && texptrs[i]==NULL; i--) ;
  1058.    ec = i;
  1059.  
  1060.    vleft() ; voutln("LIGTABLE") ;
  1061.    for (i=bc; i<=ec; i++)
  1062.       if (ai=texptrs[i]) {
  1063.          unlabeled = 1 ;
  1064.          if (uppercase[i]==NULL) /* omit ligatures from smallcap lowercase */
  1065.             for (nlig=ai->ligs; nlig; nlig=nlig->next)
  1066.                if (asucc=findadobe(nlig->succ))
  1067.                   if (asucc->texnum>=0)
  1068.                      if (asub=findadobe(nlig->sub))
  1069.                         if (asub->texnum>=0) {
  1070.                            if (unlabeled) {
  1071.                               voutln2("(LABEL %s)", vchar(i)) ;
  1072.                               unlabeled = 0 ;
  1073.                            }
  1074.                            voutln3("(LIG %s O %o)", vchar(asucc->texnum),
  1075.                                 asub->texnum) ;
  1076.                         }
  1077.          for (nkern = (uppercase[i] ? uppercase[i]->kerns : ai->kerns);
  1078.                     nkern; nkern=nkern->next)
  1079.             if (asucc=findadobe(nkern->succ))
  1080.                if (asucc->texnum>=0)
  1081.                   if (uppercase[asucc->texnum]==NULL) {
  1082.                      if (unlabeled) {
  1083.                         voutln2("(LABEL %s)", vchar(i)) ;
  1084.                         unlabeled = 0 ;
  1085.                      }
  1086.                      if (uppercase[i]) {
  1087.                         if (lowercase[asucc->texnum]) {
  1088.                            voutln3("(KRN %s R %.1f)",
  1089.                                  vchar(lowercase[asucc->texnum]->texnum),
  1090.                                  0.8*nkern->delta) ;
  1091.                         } else voutln3("(KRN %s R %.1f)",
  1092.                                  vchar(asucc->texnum), 0.8*nkern->delta) ;
  1093.                      } else {
  1094.                         voutln3("(KRN %s R %d)", vchar(asucc->texnum),
  1095.                                 nkern->delta) ;
  1096.                         if (lowercase[asucc->texnum])
  1097.                            if (lowercase[asucc->texnum]->texnum>=0)
  1098.                               voutln3("(KRN %s R %.1f)",
  1099.                                 vchar(lowercase[asucc->texnum]->texnum),
  1100.                                 0.8*nkern->delta) ;
  1101.                      }
  1102.                   }
  1103.          if (! unlabeled) voutln("(STOP)") ;
  1104.       }
  1105.    vright() ;
  1106.  
  1107.    for (i=bc; i<=ec; i++)
  1108.       if (ai=texptrs[i]) {
  1109.          vleft() ; fprintf(vplout, "CHARACTER %s", vchar(i)) ;
  1110.          if (*vcharbuf=='C') {
  1111.             voutln("") ;
  1112.          } else
  1113.             voutln2(" (comment %s)", ai->adobename) ;
  1114.          if (uppercase[i]) {
  1115.             ai=uppercase[i] ;
  1116.             voutln2("(CHARWD R %.1f)", 0.8 * (ai->width)) ;
  1117.             if (ht=texheight(ai)) voutln2("(CHARHT R %.1f)", 0.8 * ht) ;
  1118.             if (ai->lly) voutln2("(CHARDP R %.1f)", -0.8 * ai->lly) ;
  1119.             if (ai->urx > ai->width)
  1120.                voutln2("(CHARIC R %.1f)", 0.8 * (ai->urx - ai->width)) ;
  1121.          } else {
  1122.             voutln2("(CHARWD R %d)", ai->width) ;
  1123.             if (ht=texheight(ai)) voutln2("(CHARHT R %d)", ht) ;
  1124.             if (ai->lly) voutln2("(CHARDP R %d)", -ai->lly) ;
  1125.             if (ai->urx > ai->width)
  1126.                voutln2("(CHARIC R %d)", ai->urx - ai->width) ;
  1127.          }
  1128.          if (ai->adobenum != i || uppercase[i]) {
  1129.             vleft() ; voutln("MAP") ;
  1130.             if (uppercase[i]) voutln("(SELECTFONT D 1)") ;
  1131.             if (ai->pccs) {
  1132.                xoff = 0 ; yoff = 0 ;
  1133.                for (npcc = ai->pccs; npcc; npcc=npcc->next)
  1134.                   if (api=findadobe(npcc->partname))
  1135.                      if (api->texnum>=0) {
  1136.                         if (npcc->xoffset != xoff) {
  1137.                            if (uppercase[i]) {
  1138.                               voutln2("(MOVERIGHT R %.1f)",
  1139.                                       0.8 * (npcc->xoffset - xoff)) ;
  1140.                            } else voutln2("(MOVERIGHT R %d)",
  1141.                                       npcc->xoffset - xoff) ;
  1142.                            xoff = npcc->xoffset ;
  1143.                         }
  1144.                         if (npcc->yoffset != yoff) {
  1145.                            if (uppercase[i]) {
  1146.                               voutln2("(MOVEUP R %.1f)",
  1147.                                       0.8 * (npcc->yoffset - yoff)) ;
  1148.                            } else voutln2("(MOVEUP R %d)",
  1149.                                       npcc->yoffset - yoff) ;
  1150.                            yoff = npcc->yoffset ;
  1151.                         }
  1152.                         voutln2("(SETCHAR O %o)", api->adobenum) ;
  1153.                         xoff += texptrs[api->texnum]->width ;
  1154.                      }
  1155.             } else voutln2("(SETCHAR O %o)", ai->adobenum) ;
  1156.             vright() ;
  1157.          }
  1158.          vright() ;
  1159.       }
  1160.    if (level) error("! I forgot to match the parentheses") ;
  1161. }
  1162.  
  1163. void
  1164. openfiles(argc, argv)
  1165. int argc ;
  1166. char *argv[] ;
  1167. {
  1168.    register int lastext ;
  1169.    register int i ;
  1170.    extern void exit() ;
  1171.    tfmout = (FILE *)NULL ;
  1172.  
  1173.    if (argc == 1) {
  1174.       (void)printf("afm2tfm 5.36, Copyright 1990 by Radical Eye Software\n") ;
  1175.       (void)printf("Adobe-encoding version mods, 1991, by Mario Wolczko\n");
  1176.       (void)
  1177.         printf("Usage: afm2tfm foo[.afm] [-v|-V bar[.vpl]] [foo[.tfm]]\n") ;
  1178.      exit(0) ;
  1179.    }
  1180.  
  1181.    (void)sprintf(titlebuf, "%s %s", argv[0], argv[1]) ;
  1182.    (void)strcpy(inname, argv[1]) ;
  1183.    lastext = -1 ;
  1184.    for (i=0; inname[i]; i++)
  1185.       if (inname[i] == '.')
  1186.          lastext = i ;
  1187.       else if (inname[i] == '/' || inname[i] == ':')
  1188.          lastext = -1 ;
  1189.    if (lastext == -1) (void)strcat(inname, ".afm") ;
  1190.    if ((afmin=fopen(inname, "r"))==NULL)
  1191.       error("! can't open afm input file") ;
  1192.  
  1193.    while (argc>3 && *argv[2]=='-') {
  1194.       switch (argv[2][1]) {
  1195. case 'V': makevpl++ ;
  1196. case 'v': makevpl++ ;
  1197.          (void)strcpy(outname, argv[3]) ;
  1198.          lastext = -1 ;
  1199.          for (i=0; outname[i]; i++)
  1200.             if (outname[i] == '.')
  1201.                lastext = i ;
  1202.             else if (outname[i] == '/' || outname[i] == ':')
  1203.                lastext = -1 ;
  1204.          if (lastext == -1) (void)strcat(outname, ".vpl") ;
  1205.          if ((vplout=fopen(outname, WRITEBIN))==NULL)
  1206.             error("! can't open vpl output file") ;
  1207.          break ;
  1208. case 'e': if (sscanf(argv[3], "%f", &efactor)==0 || efactor<0.01)
  1209.             error("! Bad extension factor") ;
  1210.          break ;
  1211. case 's': if (sscanf(argv[3], "%f", &slant)==0)
  1212.             error("! Bad slant parameter") ;
  1213.          break ;
  1214. case 't':  /* get tfm name if present */
  1215.          (void)strcpy(outname, argv[3]) ;
  1216.          lastext = -1 ;
  1217.          for (i=0; outname[i]; i++)
  1218.             if (outname[i] == '.')
  1219.                lastext = i ;
  1220.             else if (outname[i] == '/' || outname[i] == ':')
  1221.                     lastext = -1 ;
  1222.         if (lastext == -1) {
  1223.            lastext = strlen(outname) ;
  1224.            (void)strcat(outname, ".tfm") ;
  1225.         }
  1226.         if ((tfmout=fopen(outname, WRITEBIN))==NULL)
  1227.            error("! can't open tfm output file") ;
  1228.         break ;
  1229. default: (void)fprintf(stderr, "Unknown option %s %s will be ignored.\n",
  1230.                          argv[2], argv[3]) ;
  1231.       }
  1232.       (void)sprintf(titlebuf, "%s %s %s", titlebuf, argv[2], argv[3]) ;
  1233.       argv += 2 ;
  1234.       argc -= 2 ;
  1235.    }
  1236.  
  1237.    if (argc>3 || (argc==3 && *argv[2]=='-'))
  1238.       error("! Usage: afm2tfm foo[.afm] [-v|-V bar[.vpl]] [foo[.tfm]]") ;
  1239.          
  1240.    if (argc == 2) (void)strcpy(outname, inname) ;
  1241.    else (void)strcpy(outname, argv[2]) ;
  1242.  
  1243.    lastext = -1 ;
  1244.    for (i=0; outname[i]; i++)
  1245.       if (outname[i] == '.')
  1246.          lastext = i ;
  1247.       else if (outname[i] == '/' || outname[i] == ':' || outname[i] == '\\')
  1248.          lastext = -1 ;
  1249.    if (argc == 2) {
  1250.       outname[lastext] = 0 ;
  1251.       lastext = -1 ;
  1252.    }
  1253.    if (lastext == -1) {
  1254.       lastext = strlen(outname) ;
  1255.       (void)strcat(outname, ".tfm") ;
  1256.    }
  1257.    if (tfmout == NULL && (tfmout=fopen(outname, WRITEBIN))==NULL)
  1258.       error("! can't open tfm output file") ;
  1259.    outname[lastext] = 0 ;
  1260. /*
  1261.  *   Now we strip off any directory information, so we only use the
  1262.  *   base name in the vf file.  We accept any of /, :, or \ as directory
  1263.  *   delimiters, so none of these are available for use inside the
  1264.  *   base name; this shouldn't be a problem.
  1265.  */
  1266.    for (i=0, lastext=0; outname[i]; i++)
  1267.       if (outname[i] == '/' || outname[i] == ':' || outname[i] == '\\')
  1268.          lastext = i + 1 ;
  1269.    if (lastext)
  1270.       strcpy(outname, outname + lastext) ;
  1271. }
  1272.  
  1273. #ifndef VMS
  1274. void
  1275. #endif
  1276. main(argc, argv)
  1277. int argc ;
  1278. char *argv[] ;
  1279. {
  1280.    extern void exit() ;
  1281.  
  1282.    openfiles(argc, argv) ;
  1283.    readadobe() ;
  1284.    buildtfm() ;
  1285.    writetfm() ;
  1286.    if (makevpl) {
  1287.       assignchars() ;
  1288.       if (makevpl>1) upmap() ;
  1289.       writevpl() ;
  1290.    }
  1291.    exit(0) ;
  1292.    /*NOTREACHED*/
  1293. }
  1294.